package com.lock.immersive.exception;

import com.lock.immersive.utils.ErrorCode;
import com.lock.immersive.utils.ResponseApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public ResponseApi<?> businessExceptionHandler(BusinessException e) {
        log.error("BusinessException", e);
        return ResponseApi.fail(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(RuntimeException.class)
    public ResponseApi<?> runtimeExceptionHandler(RuntimeException e) {
        log.error("RuntimeException", e);
        throw new BusinessException(ErrorCode.SYSTEM_ERROR);
    }
}
